/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode() : val(0), next(nullptr) {}
 *     ListNode(int x) : val(x), next(nullptr) {}
 *     ListNode(int x, ListNode *next) : val(x), next(next) {}
 * };
 */
class Solution {
public:
    ListNode* swapPairs(ListNode* head) {
        ListNode * dummyHead = new ListNode();
        dummyHead->next = head;
        ListNode * cur = dummyHead;
        while(cur->next != nullptr && cur->next->next != nullptr){
            ListNode * tmp = head->next->next;

            cur->next = head->next;     // 步骤一
            head->next->next = head;    // 步骤二
            head->next = tmp;           // 步骤三

            cur = cur->next->next;      // cur移动两位，准备下一轮交换
            head = cur->next;
        }
        head = dummyHead->next;
        delete dummyHead;
        dummyHead = nullptr;
        return head;
    }
};//没写完